package com.example.membersteward.controller;

import com.example.membersteward.common.CommonResult;
import com.example.membersteward.entity.Role;
import com.example.membersteward.service.RoleService;
import com.example.membersteward.service.RoleUserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
public class RoleController {

    @Resource
    RoleService roleService;

    @Resource
    RoleUserService roleUserService;

    @PostMapping("/api/getRoleByPage")
    public CommonResult getRoleByPage(@RequestParam(defaultValue = "1") int pageNum,
                              @RequestParam(defaultValue = "10") int pageSize,
                              @RequestBody Role role) {
        return roleService.getRoleByPage(pageNum, pageSize, role);
    }

    @GetMapping("/api/deleteRoles")
    public CommonResult deleteRoles(String roleIds) {
        CommonResult commonResult = roleUserService.isAdmin();
        if (commonResult.isError()) {
            return commonResult;
        }
        return roleService.deleteRoles(roleIds);
    }
    @PostMapping("/api/insertRole")
    public CommonResult insertRole(@RequestBody Role role) {
        return roleService.insertRole(role);
    }

    @PostMapping("/api/updateRole")
    public CommonResult updateRole(@RequestBody Role role) {
        return roleService.updateRole(role);
    }

    @GetMapping("/api/getRoleIds")
    public CommonResult getRoleIds() {
        return roleService.getRoleIds();
    }
}
